/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pe.edu.pucp.views;

import java.awt.event.KeyEvent;
import java.util.ArrayList;
import javax.swing.ButtonGroup;
import javax.swing.JOptionPane;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableColumn;
import pe.edu.pucp.Servicio.Servicio_Contenedor;
import pe.edu.pucp.Servicio.Servicio_ServiciosTerminal;
import pe.edu.pucp.bean.Contenedor;
import pe.edu.pucp.bean.NoRefrigerado;
import pe.edu.pucp.bean.Refrigerado;
import pe.edu.pucp.bean.Servicio;
import pe.edu.pucp.main.Main;

/**
 *
 * @author LiziTa
 * 
 */
   
public class PanelContenedorAgregar extends javax.swing.JPanel {

    public static int rbtnRef;
    public static int rbtnNoRef;
    
    Servicio_Contenedor service = Servicio_Contenedor.get_instance();
    Servicio_ServiciosTerminal service2 = Servicio_ServiciosTerminal.get_instance();
    private static String idCont;
    
    public String getId(){
        return idCont;
    }
    
    private int variable;
    
    ContenedorTm miContenedorTM = new ContenedorTm();
    ServiciosTm miServicioTM= new ServiciosTm();
      
    public void actualizaTabla() {
        miContenedorTM.conts=service.queryAllContenedor();
        //miContenedorTM.conts=main.Main.service.queryAllObjectsContenedor();
        miContenedorTM.fireTableChanged(null);
    }
    
   
    
    private void groupButton( ) { //Bloquear los campos segun los radio buttons

        ButtonGroup bg1 = new ButtonGroup( );

        bg1.add(rbtnRefrigerado);
        
        bg1.add(rbtnNoRefrigerado);   

    }
    
    class ServiciosTm extends AbstractTableModel{

        ArrayList<Servicio> servs= service2.queryAllServxCont(idCont);
        String titulos2[]={"IDSERVICIO","DESCRIPCION","PRECIO BASE","UNIDAD DE COBRO"};
        
        @Override
        public int getRowCount() {
            return servs.size();
        }

        @Override
        public int getColumnCount() {
            return 4;
        }

        @Override
        public Object getValueAt(int rowIndex, int columnIndex) {
            String res=null;
            Servicio serv= servs.get(rowIndex);
                
             switch(columnIndex){
                case 0: res = "" + serv.getId();break;
                case 1:res="" + serv.getDescripcion();break;
                case 2:res=""+serv.getPreciobase();break;
                case 3:res=""+serv.getUnidadcobro();break;
             }


            return res;
        }
        
        @Override
        public String getColumnName(int col){//COLOCA LOS TITULOS DESEADOS
            return titulos2[col];
        }
       
   }
    
    class ContenedorTm extends AbstractTableModel{

        ArrayList<Contenedor> conts = service.queryAllContenedor();
        String titulos[]={"CODIGO","PESO NETO","PESO BRUTO","VOLUMEN","DESCRIPCION MERCADERIA","TARA","TIPOCONTENEDOR","MOTOR","TEMPERATURA","TIPO CONTENIDO","ESTADO"};
        
        
        @Override
        public int getRowCount() {
            return conts.size();
        }

        @Override
        public int getColumnCount() {
            return 11 ;
        }

        @Override
       public Object getValueAt(int rowIndex, int columnIndex) {            
            String res=null;
            Contenedor cont= conts.get(rowIndex);
                
             switch(columnIndex){
                 
                case 0:res = "" + cont.getId();break;
                case 1:res = "" + cont.getPeso_neto();break;
                case 2:res = "" + cont.getPeso_bruto();break;
                case 3:res="" + cont.getVolumen();break;
                case 4:res="" + cont.getDescripcionMerc();break;
                case 5:res="" + cont.getTara(); break;
                case 6:res=cont.getTipoContenedor();break;
                case 7: if (cont instanceof Refrigerado){
                    res="" + ((Refrigerado)cont).getMotor();break;
                }else {res="-"; break;}
                case 8:if (cont instanceof Refrigerado){
                    res="" + ((Refrigerado)cont).getTemperatura();break;
                }else {res="-"; break;}
                case 9:if (cont instanceof NoRefrigerado){
                    res="" + ((NoRefrigerado)cont).getTipoContenido();break;
                }else {res="-"; break;}
                case 10: if (cont instanceof NoRefrigerado){
                    res="" + ((NoRefrigerado)cont).getEstado();break;
                }else {res="-"; break;}
             }


         return res;
        }
        
        @Override
        public String getColumnName(int col){//COLOCA LOS TITULOS DESEADOS
            return titulos[col];
        }
        
    }
    
    
    
    
    public PanelContenedorAgregar() {
        initComponents();
        TablaContenedor.setModel(miContenedorTM);
        //TablaServiciosxContenedor.setModel(miServicioTM);
        groupButton();
        actualizaTabla();
        
    }
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        TablaContenedor = new javax.swing.JTable();
        jLabel1 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        txtId = new javax.swing.JTextField();
        txtPesoNeto = new javax.swing.JTextField();
        txtPesoBruto = new javax.swing.JTextField();
        txtVolumen = new javax.swing.JTextField();
        txtDescMercaderia = new javax.swing.JTextField();
        txtTara = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        rbtnRefrigerado = new javax.swing.JRadioButton();
        rbtnNoRefrigerado = new javax.swing.JRadioButton();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        txtMotor = new javax.swing.JTextField();
        txtTemperatura = new javax.swing.JTextField();
        txtEstado = new javax.swing.JComboBox();
        txtTipoContenido = new javax.swing.JComboBox();
        Agregar = new javax.swing.JButton();
        Cancelar = new javax.swing.JButton();

        TablaContenedor.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(TablaContenedor);

        jLabel1.setText("Tabla de Contenedores Tramarsa");

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Datos Contenedores"));

        jLabel2.setText("Código");

        jLabel3.setText("Peso Neto");

        jLabel4.setText("Peso Bruto");

        jLabel5.setText("Volumen");

        jLabel6.setText("Descripción");

        jLabel7.setText("Tara");

        txtPesoNeto.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtPesoNetoKeyTyped(evt);
            }
        });

        txtPesoBruto.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtPesoBrutoActionPerformed(evt);
            }
        });
        txtPesoBruto.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtPesoBrutoKeyTyped(evt);
            }
        });

        txtVolumen.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtVolumenKeyTyped(evt);
            }
        });

        txtDescMercaderia.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtDescMercaderiaKeyTyped(evt);
            }
        });

        txtTara.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtTaraKeyTyped(evt);
            }
        });

        jLabel13.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pe/edu/pucp/views/logo.gif"))); // NOI18N

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel4)
                            .addComponent(jLabel5))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(txtVolumen, javax.swing.GroupLayout.DEFAULT_SIZE, 102, Short.MAX_VALUE)
                            .addComponent(txtPesoBruto))
                        .addGap(102, 102, 102)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel6)
                            .addComponent(jLabel7))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(txtTara, javax.swing.GroupLayout.DEFAULT_SIZE, 103, Short.MAX_VALUE)
                            .addComponent(txtDescMercaderia))
                        .addGap(35, 35, 35))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addComponent(jLabel3))
                        .addGap(21, 21, 21)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(txtPesoNeto, javax.swing.GroupLayout.DEFAULT_SIZE, 99, Short.MAX_VALUE)
                            .addComponent(txtId))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 97, Short.MAX_VALUE)
                        .addComponent(jLabel13)
                        .addContainerGap())))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(txtId, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtPesoNeto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel3)))
                    .addComponent(jLabel13, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel6)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(txtDescMercaderia, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(txtPesoBruto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel4)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 13, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtTara, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7)
                    .addComponent(txtVolumen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5))
                .addContainerGap())
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Datos Tipo Contenedor"));

        rbtnRefrigerado.setText("Refrigerado");
        rbtnRefrigerado.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rbtnRefrigeradoActionPerformed(evt);
            }
        });

        rbtnNoRefrigerado.setText("No Refrigerado");
        rbtnNoRefrigerado.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rbtnNoRefrigeradoActionPerformed(evt);
            }
        });

        jLabel8.setText("Motor");

        jLabel9.setText("Temperatura");

        jLabel10.setText("Estado");

        jLabel11.setText("Tipo Contenido");

        txtMotor.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtMotorKeyTyped(evt);
            }
        });

        txtTemperatura.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtTemperaturaKeyTyped(evt);
            }
        });

        txtEstado.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Estado 1", "Estado 2", "Estado 3", "Estado 4", "Estado 5" }));

        txtTipoContenido.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Contenido 1", "Contenido 2", "Contenido 3", "Contenido 4", "Contenido 5", "Contenido 6", "Contenido 7" }));

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(rbtnRefrigerado)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel9)
                            .addComponent(jLabel8))
                        .addGap(10, 10, 10)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(txtMotor, javax.swing.GroupLayout.DEFAULT_SIZE, 102, Short.MAX_VALUE)
                            .addComponent(txtTemperatura))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 71, Short.MAX_VALUE)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel11)
                            .addComponent(jLabel10))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(txtEstado, 0, 99, Short.MAX_VALUE)
                            .addComponent(txtTipoContenido, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(34, 34, 34))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addComponent(rbtnNoRefrigerado)
                        .addGap(126, 126, 126))))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(rbtnRefrigerado)
                    .addComponent(rbtnNoRefrigerado))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel8)
                        .addComponent(jLabel10)
                        .addComponent(txtMotor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(txtEstado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(jLabel11)
                    .addComponent(txtTemperatura, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtTipoContenido, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(38, Short.MAX_VALUE))
        );

        Agregar.setText("Agregar");
        Agregar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                AgregarActionPerformed(evt);
            }
        });

        Cancelar.setText("Cancelar");
        Cancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CancelarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addComponent(jLabel1)
                                .addGap(0, 0, Short.MAX_VALUE))
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 482, Short.MAX_VALUE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(142, 142, 142)
                        .addComponent(Agregar)
                        .addGap(44, 44, 44)
                        .addComponent(Cancelar)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(10, 10, 10)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(Agregar)
                    .addComponent(Cancelar))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 14, Short.MAX_VALUE)
                .addComponent(jLabel1)
                .addGap(18, 18, 18)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(44, 44, 44))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void txtPesoBrutoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtPesoBrutoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtPesoBrutoActionPerformed

    private void CancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CancelarActionPerformed
        this.txtDescMercaderia.setText("");
         this.txtMotor.setText("");
         this.txtId.setText("");
         this.txtPesoBruto.setText("");
         this.txtPesoNeto.setText("");
         this.txtTara.setText("");
         this.txtTemperatura.setText("");         
         this.txtVolumen.setText("");
        
    }//GEN-LAST:event_CancelarActionPerformed

    private void AgregarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AgregarActionPerformed
         if(variable==0){
            Refrigerado refrig = new Refrigerado();
            
            refrig.setId(txtId.getText());
            refrig.setPeso_neto(Float.parseFloat(txtPesoNeto.getText()));
            refrig.setPeso_bruto(Float.parseFloat(txtPesoBruto.getText()));
            refrig.setVolumen(Float.parseFloat(txtVolumen.getText()));
            refrig.setDescripcionMerc(txtDescMercaderia.getText());
            refrig.setTara(Float.parseFloat(txtTara.getText()));
            refrig.setTipoContenedor("R");
           
            refrig.setMotor(txtMotor.getText());
            
            refrig.setTemperatura(Float.parseFloat(txtTemperatura.getText()));

            service.agregaContenedor(refrig);
           if (refrig.getId().equals("1")) JOptionPane.showMessageDialog(null,"El ID del contenedor ya ha sido ingresado"," ",JOptionPane.ERROR_MESSAGE);
           
            else 
            JOptionPane.showMessageDialog(null,"Datos agregados correctamente");
            //Main.service.sacoDocumento(id).addContenedor(refrig);

        }else{ //Agrego un contenedor no Refrigerado
            NoRefrigerado noRefrig = new NoRefrigerado();
            noRefrig.setId(txtId.getText());
            noRefrig.setPeso_neto(Float.parseFloat(txtPesoNeto.getText()));
            noRefrig.setPeso_bruto(Float.parseFloat(txtPesoBruto.getText()));
            noRefrig.setVolumen(Float.parseFloat(txtVolumen.getText()));
            noRefrig.setDescripcionMerc(txtDescMercaderia.getText());
            noRefrig.setTara(Float.parseFloat(txtTara.getText()));
            noRefrig.setTipoContenedor("N");
           
            noRefrig.setEstado((String)txtEstado.getSelectedItem());
            
            noRefrig.setTipoContenido((String)txtTipoContenido.getSelectedItem());
            
            service.agregaContenedor(noRefrig);
            if (noRefrig.getId().equals("1")) JOptionPane.showMessageDialog(null,"El ID del contenedor ya ha sido ingresado"," ",JOptionPane.ERROR_MESSAGE);
           
            else 
            JOptionPane.showMessageDialog(null,"Datos agregados correctamente");
        }
       String idCont=txtId.getText();
        String idDoc=Main.principal.doc.getPanelDocumentos1().getId();
        
//        
//        Main.principal.cont.setVisible(false);        
//        Main.principal.doc.getPanelDocumentos1().ActualizaTCont();
        actualizaTabla();
        
       
        
    }//GEN-LAST:event_AgregarActionPerformed

    private void txtMotorKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtMotorKeyTyped
   
char car = evt.getKeyChar();
if((car<'a' || car>'z') && (car<'A' || car>'Z')) evt.consume();


    }//GEN-LAST:event_txtMotorKeyTyped

    
    private void txtPesoNetoKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtPesoNetoKeyTyped
    char a=evt.getKeyChar();
String texto;
//javax.swing.JTextField jTexto = new javax.swing.JTextField();
if ( "txtPesoNeto".equals(evt.getComponent().getName()))
texto=txtPesoNeto.getText().toString();
else
texto=txtPesoNeto.getText().toString();
if ((!(a>=KeyEvent.VK_0 && a<=KeyEvent.VK_9)) && (!(a==KeyEvent.VK_PERIOD))) {
evt.consume();
}
if (a==KeyEvent.VK_PERIOD) {
if (texto.indexOf(".")>0) evt.consume();

}

      if (texto.length()>9) evt.consume();  
             // TODO add your handling code here:
    }//GEN-LAST:event_txtPesoNetoKeyTyped

    private void txtPesoBrutoKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtPesoBrutoKeyTyped
     char a=evt.getKeyChar();
String texto;
//javax.swing.JTextField jTexto = new javax.swing.JTextField();
if ( "txtPesoBruto".equals(evt.getComponent().getName()))
texto=txtPesoBruto.getText().toString();
else
texto=txtPesoBruto.getText().toString();
if ((!(a>=KeyEvent.VK_0 && a<=KeyEvent.VK_9)) && (!(a==KeyEvent.VK_PERIOD))) {
evt.consume();
}
if (a==KeyEvent.VK_PERIOD) {
if (texto.indexOf(".")>0) evt.consume();

}
       if (texto.length()>9) evt.consume(); // TODO add your handling code here:
    }//GEN-LAST:event_txtPesoBrutoKeyTyped

    private void txtVolumenKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtVolumenKeyTyped
 char a=evt.getKeyChar();
String texto;
//javax.swing.JTextField jTexto = new javax.swing.JTextField();
if ( "txtVolumen".equals(evt.getComponent().getName()))
texto=txtVolumen.getText().toString();
else
texto=txtVolumen.getText().toString();
if ((!(a>=KeyEvent.VK_0 && a<=KeyEvent.VK_9)) && (!(a==KeyEvent.VK_PERIOD))) {
evt.consume();
}
if (a==KeyEvent.VK_PERIOD) {
if (texto.indexOf(".")>0) evt.consume();

}
      if (texto.length()>9) evt.consume();  
    }//GEN-LAST:event_txtVolumenKeyTyped

    private void txtTaraKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtTaraKeyTyped
 char a=evt.getKeyChar();
String texto;
//javax.swing.JTextField jTexto = new javax.swing.JTextField();
if ( "txtTara".equals(evt.getComponent().getName()))
texto=txtTara.getText().toString();
else
texto=txtTara.getText().toString();
if ((!(a>=KeyEvent.VK_0 && a<=KeyEvent.VK_9)) && (!(a==KeyEvent.VK_PERIOD))) {
evt.consume();
}
if (a==KeyEvent.VK_PERIOD) {
if (texto.indexOf(".")>0) evt.consume();

}
if (texto.length()>9) evt.consume();
        // TODO add your handling code here:
    }//GEN-LAST:event_txtTaraKeyTyped

    private void txtTemperaturaKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtTemperaturaKeyTyped
 char a=evt.getKeyChar();
String texto;
//javax.swing.JTextField jTexto = new javax.swing.JTextField();
if ( "txtTemperatura".equals(evt.getComponent().getName()))
texto=txtTemperatura.getText().toString();
else
texto=txtTemperatura.getText().toString();
if ((!(a>=KeyEvent.VK_0 && a<=KeyEvent.VK_9)) && (!(a==KeyEvent.VK_PERIOD))) {
evt.consume();
}
if (a==KeyEvent.VK_PERIOD) {
if (texto.indexOf(".")>0) evt.consume();

}
 if (texto.length()>9) evt.consume();  
    }//GEN-LAST:event_txtTemperaturaKeyTyped

    private void txtDescMercaderiaKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtDescMercaderiaKeyTyped

            char car = evt.getKeyChar();    
if((car<'a' || car>'z') && (car<'A' || car>'Z') 
   && (car!=(char)KeyEvent.VK_SPACE))
{
   evt.consume();
}// TODO add your handling code here:
    }//GEN-LAST:event_txtDescMercaderiaKeyTyped

    private void rbtnRefrigeradoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rbtnRefrigeradoActionPerformed
  rbtnRef=0;
  variable=0;
    
    }//GEN-LAST:event_rbtnRefrigeradoActionPerformed

    private void rbtnNoRefrigeradoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rbtnNoRefrigeradoActionPerformed
    rbtnNoRef=1;
    variable=1;
        // TODO add your handling code here:
    }//GEN-LAST:event_rbtnNoRefrigeradoActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton Agregar;
    private javax.swing.JButton Cancelar;
    private javax.swing.JTable TablaContenedor;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JRadioButton rbtnNoRefrigerado;
    private javax.swing.JRadioButton rbtnRefrigerado;
    private javax.swing.JTextField txtDescMercaderia;
    private javax.swing.JComboBox txtEstado;
    private javax.swing.JTextField txtId;
    private javax.swing.JTextField txtMotor;
    private javax.swing.JTextField txtPesoBruto;
    private javax.swing.JTextField txtPesoNeto;
    private javax.swing.JTextField txtTara;
    private javax.swing.JTextField txtTemperatura;
    private javax.swing.JComboBox txtTipoContenido;
    private javax.swing.JTextField txtVolumen;
    // End of variables declaration//GEN-END:variables
}
